import request from '_r/request'

const api_name = 'user'

// 获取用户详细信息
export function getUserDetail(userId) {
	return request({
		url: `${api_name}/${parseStrEmpty(userId)}`,
		method: `get`
	})
}

// 修改用户
export function updateUser(data) {
	return request({
		url: `${api_name}`,
		method: `put`,
		data
	})
}

// 修改用户密码
export function updateUserPassword(oldPassword, newPassword) {
	const data = {
		oldPassword,
		newPassword
	}
	return request({
		url: `${api_name}/password`,
		method: `put`,
		data
	})
}

// 转换字符串，undefined,null等转化为""
export function parseStrEmpty(str) {
	if (!str || str === 'undefined' || str === 'null' || str === null) {
		return ''
	}
	return str
}
